<?php
	class CriarForm
	{
		public static function execute($objTabela)
		{
		    $tabela = $objTabela->getNomeTabela();

		    /*Iniciando a criacao do conteudo do arquivo*/
		    $conteudo  = JavaScriptParaCamposNotNull::execute($objTabela);
		    
		    $conteudo .= '<form action="../inserts/inserir_' . $tabela . '.php" method="post" name="form1" onSubmit="JavaScript:testaCamposObrigatoriosDeCliente(this);return isValid;">' . "\n";
		    $conteudo .= '<table border="0"><tr>' . "\n";

		    $asterisco  = ' valign="top"><font size="1">*</font></td>' . "\n" . '<td';
		    $pularLinha = '</div></td></tr>' . "\n";
		    $puloLinha  = true;

		    for($i = 0; $i < count($objTabela->getCampos()); $i++)
		    {
   			    /*Criando os componetes do formul�rio*/
		    	if($objTabela->getExtra($i) != 'auto_increment' && $objTabela->getCampo($i) != 'data_db')
				{
					$puloLinha = !$puloLinha;
					//$w para diminuir o comprimento da linha
					$w = $objTabela->getNomeTipoCampo($i);

					$conteudo .= "\t" . '<td';

					if($objTabela->getKey($i) == 'PRI' || $objTabela->getNull($i) != 'YES')
					{
						$conteudo .= $asterisco;
					}
					else
					{
						$conteudo .= '></td>' . "\n\t". '<td';
					}

					$conteudo .= '><div align="left"><label for="<?= $matTabelasColunas[' . "'" . $objTabela->getNomeTabela() . "'" . '][' . "'" . $objTabela->getCampo($i) . "'" . '][' . "'" . 'nome' . "'" . '] ?>"><?= $matTabelasColunas[' . "'" . $objTabela->getNomeTabela() . "'" . '][' . "'" . $objTabela->getCampo($i) . "'" . '][' . "'" . 'nome' . "'" . '] ?></label><br>' . "\n";

					if ($w != 'tinyint' && $w != 'longtext')
					{
						if ($w == 'date')
						{
							// colocando calendario
							$conteudo   .= "\t" . '<input type="text" id="<?= $matTabelasColunas[' . "'" . $objTabela->getNomeTabela() . "'" . '][' . "'" . $objTabela->getCampo($i) . "'" . '][' . "'" . 'nome' . "'" . '] ?>" name="' . $objTabela->getCampo($i) . '" maxlength="10" /><input type="button" id="btn_' . $objTabela->getCampo($i) . '" value="...">';
						}
						else
						{
							$javascript  = $GLOBALS['matJavaScript'][$objTabela->getNomeTipoCampo($i)] != '' ? $GLOBALS['matJavaScript'][$objTabela->getNomeTipoCampo($i)] : $GLOBALS['matJavaScript'][$objTabela->getCampo($i)];
							$conteudo   .= "\t" . '<input type="text" name="' . $objTabela->getCampo($i) . '" id="<?= $matTabelasColunas[' . "'" . $objTabela->getNomeTabela() . "'" . '][' . "'" . $objTabela->getCampo($i) . "'" . '][' . "'" . 'nome' . "'" . '] ?>" maxlength="<?= $matTabelasColunas[' . "'" . $objTabela->getNomeTabela() . "'" . '][' . "'" . $objTabela->getCampo($i) . "'" . '][' . "'" . 'tamanho' . "'" . '] ?>"' . $javascript . '>';
						}
					}
					else
					{
						if ($w == 'tinyint')
						{
							$conteudo .= '<input type="checkbox" name="' . $objTabela->getCampo($i) . ' id="<?= $matTabelasColunas[' . "'" . $objTabela->getNomeTabela() . "'" . '][' . "'" . $objTabela->getCampo($i) . "'" . '][' . "'" . 'nome' . "'" . '] ?>" value="1">';
						}
						else
						{
							$conteudo .= '<textarea name="' . $objTabela->getCampo($i) . ' id="<?= $matTabelasColunas[' . "'" . $objTabela->getNomeTabela() . "'" . '][' . "'" . $objTabela->getCampo($i) . "'" . '][' . "'" . 'nome' . "'" . '] ?>" cols="38" rows="3"></textarea>';
						}
					}
					if($puloLinha)
					{
						$conteudo .= $pularLinha;
					}
					else
					{
						$conteudo .= '</div></td>' . "\n";
					}
				}
		    }

		    if(!$puloLinha)
			{
				$conteudo .= '</tr>';
			}

			$ultimaLinha = "\t" . '<tr><td colspan="4"><br><font size="1">* preenchimento obrigat&oacute;rio</font><br>' . "\n" . '<table width="100%" border="0" cellspacing="0">' . "\n" . '<tr>' . "\n\t" . '<td><div align="right"><input type="button" name="Voltar" value="Voltar" onClick="JavaScript:history.back(-1)"></div></td>' . "\n\t" .  '<td width="10">&nbsp;</td>' . "\n\t" . '<td><input type="submit" name="Enviar" value="Enviar"></td>' . "\n" . '</tr></table>' . "\n" . '</td></tr></table>' . "\n" . '</form>' . "\n";
			$javascriptCalendarios = '';

			for($i = 0; $i < count($objTabela->getCampos()); $i++)
		    {
   			    /*Criando os componetes do formul�rio*/
		    	if($objTabela->getExtra($i) != 'auto_increment' &&
		    	   $objTabela->getCampo($i) != 'data_db'        &&
		    	   $objTabela->getTipo($i)  == 'date')
				{
					$javascriptCalendarios .= 'Calendar.setup' . "\n" . '(' . "\n\t" . '{' . "\n\t\t" . 'inputField : "' . '<?= $matTabelasColunas[' . "'" . $objTabela->getNomeTabela() . "'" . '][' . "'" . $objTabela->getCampo($i) . "'" . '][' . "'" . 'nome' . "'" . '] ?>' . '",' . "\n";
					$javascriptCalendarios .= "\t\t" . 'ifFormat : "%d/%m/%Y",' . "\n\t\t" . 'button : "btn_' . $objTabela->getCampo($i) . '"' . "\n\t" . '}' . "\n" . ');' . "\n";
				}
		    }
		    
		    if ($javascriptCalendarios != '')
		    {
		    	$javascriptCalendarios = '<script type="text/javascript">' . "\n" . $javascriptCalendarios . '</script>' . "\n";
		    }

		    $conteudo .= $ultimaLinha . $javascriptCalendarios;

		    return $conteudo;
		}
	}
?>